#include <bits/stdc++.h>
using namespace std;

using node = tuple<int, int, int, int>;
const int N = 33;

int n, m, d[N][N][N][N];

char s[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    
    int yx, yy, bx, by;
    
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++) {
            cin >> s[i][j];
            if(s[i][j] == 'Y') {
                yx = i;
                yy = j;
            }else if(s[i][j] == 'B') {
                bx = i;
                by = j;
            }
        }
    
    memset(d, -1, sizeof d);

    queue<node> q;
    d[yx][yy][bx][by] = 0;
    q.push({yx, yy, bx, by});
    while(q.size()) {
        auto [yx, yy, bx, by] = q.front();
        q.pop();
    }

    return 0;
}